WebLogic CommonJ Framework or WebLogic Work Manager API
The WebLogic CommonJ framework, sometimes referred to as the WebLogic Work Manager API, is not an official standard and, as such, is not supported in JBoss Application Server. JBoss instead supports the Java EE 6 standard WorkManager API (javax.resource.work.WorkManager). WebLogic applications that use the WebLogic version of the framework will need to replace this code.
The best approach is to implement a JCA Resource Adapter with the required business interface to replace the CommonJ code. The JCA Resource Adapter specification can be found here: JSR 322: JavaTM EE Connector Architecture 1.6 . The IronJacamar tool can help you get started writing a Resource Adapter. IronJacamar provides a WorkManager Resource Adapter in its test suite. Information about the WorkManager Interface can be found here: http://www.ironjacamar.org/doc/api/spec/1.7/javax/resource/spi/work/WorkManager.html.
Replace WebLogic Virtual Directories
WebLogic provides the ability to specify an alternate document root for files in a Web application using the <virtual-directory-mapping> element in the weblogic.xml proprietary descriptor file. JBoss AS 7 does not support this feature. If an application uses this feature, you must do one of the following:for JBoss to find the documents.
-
For JBoss servers running on Linux, you can set up symbolic links (symlinks) for the the documents defined with alternate roots.
-
You must modify the application packaging structure and move the files to the well-known standard Java EE 6 location.
Replace WebLogic ApplicationLifecycleListener Code
The WebLogic ApplicationLifecycleListener abstract class is used to perform functions or schedule jobs at application server start and stop. The following table shows the four stages in the application lifecycle available for listener registration in WebLogic:
|
WebLogic Method
|
Description
|
|
void preStart(ApplicationLifecycleEvent evt)
|
Provides hooks for listeners before the application finishes initialization.
|
|
void postStart(ApplicationLifecycleEvent evt)
|
Provides hooks for listeners after the application finishes initialization.
|
|
void preStop(ApplicationLifecycleEvent evt)
|
Provides hooks for listeners when the application begins the shutdown process.
|
|
void postStop(ApplicationLifecycleEvent evt)
|
Provides hooks for listeners after the application ends the shutdown process.
|
Replace Application Start and Stop Events
In JBoss Enterprise Application Platform 6, there is no equivalent to intercept the preStart or preStop processing, but you can use one of the following methods to achieve results similar to the postStart and postStop methods.
1. Create a ServletContextListener
The ServletContextListener class provides two methods that are analoguous to postStart() and postStop() methods in the WebLogic ApplicationLifecycleListener class. Since the code must access the context root of the application using the ServletContext, the servlet must be deployed to a WAR file. The following is an example of code that uses the ServletContextListener to perform tasks after application server start and stop:
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class ContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent evt) {
ServletContext ctx = evt.getServletContext();
System.out.println("contextInitialized(): ServerInfo: " +
ctx.getServerInfo() + " " + System.currentTimeMillis());
System.out.println("contextInitialized(): ContextPath: " +
ctx.getContextPath() + " " + System.currentTimeMillis());
}
@Override
public void contextDestroyed(ServletContextEvent evt) {
ServletContext ctx = evt.getServletContext();
System.out.println("contextDestroyed(): ServerInfo: " +
ctx.getServerInfo() + " " + System.currentTimeMillis());
System.out.println("contextDestroyed(): ContextPath: " +
ctx.getContextPath() + " " + System.currentTimeMillis());
}
}
2. Create a Singleton Stateless Session Bean
Create a singleton bean using the @Singleton annotation. Use the @Startup annotation to tell the container to initialize the singleton session bean at application start. Use the @PostConstruct annotation to specify the method to invoke at the start of the application lifecyle and the @PostDestroy annotation to specify the method to invoke at the end of the application life cycle. The following is an example of a stateless session bean:
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;
@Startup
@Singleton
public class StartupBean
{
@PostConstruct
void startup() {
System.out.println("startup()", "@PostContruct called");
}
@PreDestroy
void shutdown() {
System.out.println("shutdown()", "@PreDestroy called");
}
}
WebLogic Proprietary Annotations
WebLogic provides its own proprietary servlet and filter annotations for dependency injection. If the application uses them, they must be replaced the standard Java EE 6 annotations. The following table contains a mapping of the most commonly used WebLogic annotations to the corresponding standard Java EE 6 annotation.
|
WebLogic
|
Java EE 6 Equivalent
|
Java EE 6 Import
|
|
@WLServlet
|
@WebServlet
|
javax.servlet.annotation.WebServlet
|
|
@WLFilter
|
@WebFilter
|
javax.servlet.annotation.WebFilter
|
|
@WLInitParam
|
@WebInitParam
|
javax.servlet.annotation.WebParam
|
Be sure to modify the attributes for the annotations to conform to the standard attribute names. Details about the attributes are listed below. For more information on the Java EE 6 servlet annotations, see the javax.servlet.annotation javadoc .
You must also remove the WebLogic imports and JAR.
Replace the Proprietary WebLogic @WLServlet Annotation
You must replace the proprietary WebLogic @WLServlet annotation with the standard Java EE 6 @WebServlet equivalent. Before you replace the code, you must understand how to map the attribute values. The following table shows the mapping of the WebLogic @WLServlet annotation attributes to the Java EE 6 @WebServlet equivalents.
|
WebLogic Attribute Name
|
Java EE 6 Equivalent
|
Description / Comments
|
|
String displayName
|
String displayName
|
Display name for the Servlet
|
|
String description
|
String description
|
Servlet description
|
|
String icon
|
String smallicon -or-String largeicon
|
The icon location
|
|
String name
|
String name
|
The Servlet name
|
|
WLInitParam[] initParams
|
WebInitParam[] initParams
|
Servlet initialization parameters
|
|
int loadOnStartup
|
int loadOnStartup
|
Whether the Servlet should load on server start
|
|
String runAs
|
No equivalent attribute
|
The run-as User for the Servlet. There are 3 options for replacement detailed below.
|
|
String[] mapping
|
String[] urlPatterns or String[] value
|
The Servlet URL pattern
|
The following is a list of options for replacement of the runAs attribute:
-
Use the javax.annotation.security.RunAs annotation in the class file.
-
Define the run-as element for the Servlet in the application's web.xml file.
-
Define the run-as element in a application's {{web-fragments.xml} file. See sections 8.2.1 through 8.2.3 of the Servlet 3.0 specification for further information about web-fragments.
Here is an example of WebLogic code that uses the @WLServlet annotation:
import weblogic.servlet.annotation.WLServlet;
@WLServlet (
name = "catalog",
runAs = "SuperEditor"
initParams = {
@WLInitParam (name="catalog", value="spring"),
@WLInitParam (name="language", value="English")
},
mapping = {"/catalog/*"}
)
public class MyCatalogServlet extends HttpServlet { . . . }
Here is the equivalent code that uses the standard @WebServlet annotation:
import javax.annotation.security.RunAs;
import javax.servlet.annotation.WebServlet;
@WebServlet (
name = "catalog",
initParams = {
@WebInitParam (name="catalog", value="spring"),
@WLInitParam (name="language", value="English")
},
urlPatterns = "/catalog/*"
)
@RunAs("SuperEditor")
public class MyCatalogServlet extends HttpServlet { . . . }
Replace the Proprietary WebLogic @WLFilter Annotation
You must replace the proprietary WebLogic @WLFilter annotation with the standard Java EE 6 @WebFilter equivalent. Before you replace the code, you must understand how to map the attribute values. The following table shows the mapping of the WebLogic @WLFilter annotation attributes to the Java EE 6 @WebFilter equivalents.
|
WebLogic Attribute Name
|
Java EE 6 Equivalent
|
Description / Comments
|
|
String displayName
|
String displayName
|
Display name for the Servlet
|
|
String description
|
String description
|
Servlet description
|
|
String icon
|
String smallicon -or-String largeicon
|
The icon location
|
|
String name
|
String name
|
The Servlet name
|
|
WLInitParam[] initParams
|
WebInitParam[] initParams
|
Servlet initialization parameters
|
|
String[] mapping
|
String[] urlPatterns or String[] value
|
The Servlet URL pattern
|
|
No equivalent attribute
|
DispatcherTypes[] dispatcherTypes
|
The dispatcher types to which the filter applies
|
|
No equivalent attribute
|
String[] servletNames
|
The names of the servlets to which the filter applies
|
Here is an example of WebLogic code that uses the @WLFilter annotation:
import weblogic.servlet.annotation.WLFilter;
import weblogic.servlet.annotation.WLInitParam;
@WLFilter (
name = "catalogFilter",
initParams = { @WLInitParam(name="catalog", value="winter") }
mapping = {"/catalog/*"}
)
public class MyFilter implements Filter { . . . }
Here is the equivalent code that uses the standard @WebFilter annotation:
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
@WebFilter (
filterName = "catalogFilter",
initParams = { @WebInitParam(name="catalog", value="winter") }
urlPatterns = {"/catalog/*"}
)
public class MyFilter implements Filter { . . . }
Replace the Proprietary WebLogic @WLInitParam Annotation
You must replace the proprietary WebLogic @WLInitParam annotation with the standard Java EE 6 @WebInitParam equivalent. Before you replace the code, you must understand how to map the attribute values. The following table shows the mapping of the WebLogic @WLInitParam annotation attributes to the Java EE 6 @WebInitParam equivalents.
|
WebLogic Attribute Name
|
Java EE 6 Equivalent
|
Description / Comments
|
|
String name
|
String name
|
Name of the initialization parameter
|
|
String value
|
String value
|
Value of the initialization parameter
|
|
No equivalent attribute
|
String description
|
Optional description of the initialization parameter
|
Here is an example of WebLogic code that uses the @WLInitParam annotation:
import weblogic.servlet.annotation.WLFilter;
import weblogic.servlet.annotation.WLInitParam;
@WLFilter (
name = "catalogFilter",
initParams = { @WLInitParam(name="catalog", value="winter") }
mapping = {"/catalog/*"}
)
public class MyFilter implements Filter { . . . }
Here is the equivalent code that uses the standard @WebInitParam annotation:
import javax.servlet.annotation.WebFilter;
import avax.servlet.annotation.WebInitParam;
@WebFilter (
filterName = "catalogFilter",
initParams = { @WebInitParam(name="catalog", value="winter", description="winter catalog") }
urlPatterns = {"/catalog/*"}
)
public class MyFilter implements Filter { . . . }
WebLogic Specific Oracle Datasources
TODO: section is not complete.